package com.usj.dcalvo.ecommerce.security;

/**
 *
 * @author Javandengi
 */

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.usj.dcalvo.ecommerce.action.LoginAction;
import com.usj.dcalvo.ecommerce.bean.UsuarioBean;

public class InterAutenticacion implements Interceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2520717597696806042L;

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Map session = actionInvocation.getInvocationContext().getSession();
		UsuarioBean usuarioBean = (UsuarioBean) session.get("usuario");
		if (usuarioBean == null && !(actionInvocation.getAction() instanceof LoginAction)) {
			return Action.LOGIN;
		} else {
			Action action = (Action) actionInvocation.getAction();
			// if (action instanceof UsuarioBeanHabilitado) {
			// ((UsuarioBeanHabilitado) action).setUsuarioBean(UsuarioBean);
			// }
			return actionInvocation.invoke();
		}
	}
}
